package com.example.gfsquadwebviewproject.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

public abstract class BaseFragment extends Fragment {

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

    }

    @Override
    public void onAttach(Activity activity) {
        iBaseFragmentBack=(IBaseFragmentBack)activity;
        super.onAttach(activity);
    }

    //变更当前显示的Fragment
    public void showFragment(Fragment fragment_current, Fragment fragment_next,String fragment_next_TAG,int id) {
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        if(fragment_next.isAdded()){
            fragmentTransaction
                    .hide(fragment_current)
                    .show(fragment_next)
                    .addToBackStack(fragment_current.getTag())
                    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)// 设置转换动画
                    .commitAllowingStateLoss();// 提交事务
        }else {
            fragmentTransaction
                    .hide(fragment_current)// 隐藏fragment_current
                    .add(id, fragment_next,fragment_next_TAG)
                    .addToBackStack(fragment_current.getTag())
                    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
                    .commitAllowingStateLoss();
        }
    }


    public IBaseFragmentBack iBaseFragmentBack;
}